import requestProxy from '@/utils/request';
const { request } = requestProxy;
function jsonParse(str, defaultValue = undefined) {
  if (!str) return defaultValue;
  try {
    return JSON.parse(str);
  } catch (error) {
    return defaultValue;
  }
}
// 合同列表
export function getList(params, cancelToken) {
  return request({
    url: '/admin/contract/list',
    method: 'get',
    params,
    cancelToken
  });
}
// 合同管理 - 合同列表
export function getManageList(params) {
  return request({
    url: '/admin/contractManage/list',
    method: 'get',
    params
  });
}

// 合同管理 - 统计看板
export function getManageStatistics(params) {
  return request({
    url: 'admin/contractManage/statistics',
    method: 'get',
    params
  });
}

// 合同详情
export function getContractDetail(id) {
  return request({
    url: 'admin/contract/detail/' + id,
    method: 'get'
  });
}
// 合同详情-生成合同编号
export function generateCode(params) {
  return request({
    url: '/admin/contract/generateCode',
    method: 'get',
    params
  });
}

// 删除合同
export function deleteContract(id) {
  return request({
    url: '/admin/contract/delete/' + id,
    method: 'delete'
  });
}

// 新增合同
export function createContract(data) {
  return request({
    url: 'admin/contract/create',
    method: 'post',
    data
  });
}
// 新增历史合同
export function createHistoryContract(data) {
  return request({
    url: 'admin/contract/history/create',
    method: 'post',
    data
  });
}
// 编辑合同
export function editContract(id, data) {
  return request({
    url: 'admin/contract/edit/' + id,
    method: 'put',
    data
  });
}

// 封存合同
export function freezeContract(id) {
  return request({
    url: 'admin/contract/archive/' + id,
    method: 'post'
  });
}

// 业务类型
export function getBusinessType(params) {
  return request({
    url: '/admin/contract/types',
    method: 'get',
    params
  });
}

// 批量删除合同
export function batchdelContract(data) {
  return request({
    url: '/admin/contract/delete/batch',
    method: 'delete',
    data
  });
}

// 流程设置-分组列表
export function getProcessManagement(params) {
  return request({
    url: '/admin/processManagement/list',
    method: 'get',
    params
  });
}

// 流程设置-分组排序
export function orderProcessManagement(data) {
  return request({
    url: '/admin/processManagement/groupList/order',
    method: 'put',
    data
  });
}

// 流程设置-分组新增
export function addProcessManagement(data) {
  return request({
    url: '/admin/processManagement/groupList/add',
    method: 'post',
    data
  });
}

// 流程设置-分组编辑
export function editProcessManagement(data) {
  return request({
    url: '/admin/processManagement/groupList/edit',
    method: 'put',
    data
  });
}

// 流程设置-分组删除
export function deleteProcessGroup(id) {
  return request({
    url: `/admin/processManagement/groupList/delete/${id}`,
    method: 'delete'
  });
}

// 流程设置-自定义流程删除
export function deleteProcess(id) {
  return request({
    url: `/admin/processManagement/list/delete/${id}`,
    method: 'delete'
  });
}

// 获取流程模板
export function processManagementDetail(params) {
  return new Promise((resolve, reject) => {
    request({
      url: '/admin/processManagement/detail/' + params.id,
      method: 'get',
      params
    }).then(res => {
      if (res.data && typeof res.data === 'string') {
        res.data = jsonParse(res.data, []);
      }
      resolve(res);
    }).catch(err => {
      reject(err);
    });
  });
}

export function processManagementList(params) {
  return request({
    url: '/admin/processManagement/all',
    method: 'get',
    params
  });
}

export function editProcess(data) {
  return request({
    url: '/admin/processManagement/edit',
    method: 'put',
    data
  });
}

export function addProcess(data) {
  return request({
    url: '/admin/processManagement/add',
    method: 'post',
    data
  });
}

// 合同管理 - 流程列表
export function getProcessList(params) {
  return request({
    url: '/admin/contract/process/list',
    method: 'get',
    params
  });
}

// 合同管理 - 流程 - 撤销
export function postRevocation(data) {
  return request({
    url: '/admin/contract/process/revocation',
    method: 'post',
    data
  });
}

// 合同管理 - 流程 - 撤回
export function postRecall(data) {
  return request({
    url: '/admin/contract/process/recall',
    method: 'post',
    data
  });
}

// 合同管理 - 流程 - 审批
export function postProcessAudit(data) {
  return request({
    url: '/admin/contract/process/audit',
    method: 'post',
    data
  });
}

export function getAuditorList(params) {
  return request({
    url: '/admin/processManagement/users',
    method: 'get',
    params
  });
}
export function getAuditorButtonList(params) {
  return request({
    url: '/admin/processManagement/button/users',
    method: 'get',
    params
  });
}
export function getContractListTabs(params, cancelToken) {
  return request({
    url: '/admin/contract/list/tab',
    method: 'get',
    params,
    cancelToken
  });
}

// 合同管理-列表tabs
export function getContractManageListTabs(params) {
  return request({
    url: '/admin/contractManage/list/tab',
    method: 'get',
    params
  });
}

export function getAduitorInfo(type) {
  return request({
    url: `/admin/contract/${type}/aduitorInfo`,
    method: 'get'
  });
}

// 合同详情 - 关联订单列表
export function getContractRelatedOrder(params) {
  return request({
    url: '/admin/contract/detail/relatedList',
    method: 'get',
    params
  });
}

// 合同详情 - 关联实际订单
export function storeRealOrders(data) {
  return request({
    url: '/admin/contract/realOrders/store',
    method: 'post',
    data
  });
}

// 流程管理-获取流程高级设置详情
export function getAdvancedSet(id) {
  return request({
    url: `/admin/processManagement/advancedSet/${id}`,
    method: 'get'
  });
}

// 流程管理-流程高级设置
export function setAdvancedSet(id, data) {
  return request({
    url: `/admin/processManagement/advancedSet/${id}`,
    method: 'put',
    data
  });
}

// 流程管理-审批进程
export function auditSchedule(id) {
  return request({
    url: `/admin/contract/schedule/${id}`,
    method: 'get'
  });
}

// 流程管理-审批进程-添加加签人
export function scheduleCounterSign(data) {
  return request({
    url: '/admin/contract/schedule/countersign',
    method: 'post',
    data
  });
}

// 合同审批-转交
export function sumbDeliverTo(data) {
  return request({
    url: '/admin/contract/deliverTo',
    method: 'post',
    data
  });
}

// 合同审批-合同回收
export function contractRecycleApi(data) {
  return request({
    url: '/admin/contract/recycle',
    method: 'post',
    data
  });
}

// 合同审批-高级撤回
export function contractHigherRecall(data) {
  return request({
    url: '/admin/contract/higherRecall',
    method: 'post',
    data
  });
}

// 合同审批-重新提交
export function contractResubmit(data) {
  return request({
    url: '/admin/contract/resubmit',
    method: 'post',
    data
  });
}

// 流程管理-催办通知
export function pressSendMsg(data) {
  return request({
    url: 'admin/processManagement/press',
    method: 'post',
    data
  });
}

// 流程管理-取消加急
export function cancelPress(data) {
  return request({
    url: 'admin/processManagement/cancelPress',
    method: 'post',
    data
  });
}

// 合同评论列表
export function getComments(params) {
  return request({
    url: '/admin/contract/comments/list',
    method: 'get',
    params
  });
}

// 发表评论
export function legalCommentAdd(data) {
  return request({
    url: '/admin/contract/comments/add',
    method: 'post',
    data
  });
}

// 审批审批转交提交
export function processHandoverModify(data) {
  return request({
    url: '/admin/processManagement/handover/modify',
    method: 'post',
    data
  });
}

// 审批审批转交交接项列表
export function getHandoverInfoList(params) {
  return request({
    url: '/admin/processManagement/handoverInfo/list',
    method: 'get',
    params
  });
}

// 审批审批转交交接项列表
export function getProcessRejectList(params) {
  return request({
    url: '/admin/processManagement/rejectList',
    method: 'get',
    params
  });
}

// 获取最新审批信息
export function getApproveLatestInfo(data) {
  return request({
    url: '/admin/contract/latestInfo',
    method: 'post',
    data
  });
}

// 审批详情页审批单切换
export function getToggleInfo(data) {
  return request({
    url: 'admin/contract/toggleInfo',
    method: 'post',
    data
  });
}

// 表单提交、获取审批流
export function formSubmit(data) {
  return request({
    url: '/admin/contract/formSubmit',
    method: 'post',
    data
  });
}

// 用于请求超时流程转交处理是否完毕
export function transferOver(processId) {
  return request({
    url: `/admin/contract/check/transfer/${processId}`,
    method: 'get'
  });
}

// 合同模板-列表
export function queryTemplateList(params) {
  return request({
    url: '/admin/contract/template/list',
    method: 'get',
    params
  });
}

// 合同模板-添加文件夹
export function storeContractTemplate(data) {
  return request({
    url: '/admin/contract/template/store',
    method: 'post',
    data
  });
}

// 合同模板-编辑文件夹
export function editContractTemplate(data) {
  return request({
    url: '/admin/contract/template/edit',
    method: 'put',
    data
  });
}

// 合同模板-删除文件
export function deleteContractTemplate(data) {
  return request({
    url: '/admin/contract/template/delete',
    method: 'delete',
    data
  });
}

// 合同模板-编辑模板说明
export function editTemplateDesc(data) {
  return request({
    url: '/admin/contract/templateDesc/edit',
    method: 'post',
    data
  });
}

// 合同模板-获取填充数据模板地址
export function queryFillFilePath(data) {
  return request({
    url: '/admin/contract/template/preview',
    method: 'post',
    data
  });
}

// 合同模板-获取最后一次模板信息
export function getLastTemplateInfo(type) {
  return request({
    url: `/admin/contract/lastTemplate/${type}`,
    method: 'get'
  });
}

// 流程设置-提交批量设置人员
export function processBatchSet(data) {
  return request({
    url: '/admin/processManagement/batchSet',
    method: 'post',
    data
  });
}

// 新建合同-获取签约对方来源
export function getSignUpOtherOptions(params) {
  return request({
    url: '/admin/contract/signUpOther/list',
    method: 'get',
    params
  });
}

// 最近使用审批模块列表
export function getRecentlyUsedList(params = {}) {
  return request({
    url: '/admin/processManagement/recentlyUsed/list',
    method: 'get',
    params
  });
}

// 审批流程-增加抄送人员
export function handleSender(data) {
  return request({
    url: 'admin/processManagement/sendMsg',
    method: 'post',
    data
  });
}

// 流程设置-转交管理员
export function transferAdministrator(data) {
  return request({
    url: '/admin/processManagement/transferAdministrator',
    method: 'post',
    data
  });
}

export function commentDelete(data) {
  return request({
    url: `/admin/common/comments/delete/${data.id}`,
    method: 'delete',
    data
  });
}

// 合同 - 编辑盖章类型
export function editStampType(data) {
  return request({
    url: 'admin/contract/stampType/edit',
    method: 'post',
    data
  });
}

// 合同审批 - 附件记录列表
export function getContractAttachmentList(id) {
  return request({
    url: `admin/contract/attachment/list/${id}`,
    method: 'get'
  });
}

// 合同审批 - 附件记录删除
export function deleteAttachment(id) {
  return request({
    url: `admin/contract/attachment/delete/${id}`,
    method: 'delete'
  });
}

// 合同审批 - doc、docx附件对比列表
export function getAttachmentDiffList(id) {
  return request({
    url: `admin/contract/attachmentDiff/list/${id}`,
    method: 'get'
  });
}

// 合同审批 - 获取附件内容
export function getAttachmentContent(params) {
  return request({
    url: 'admin/contract/attachmentContent',
    method: 'get',
    params
  });
}

// 获取可见人员列表
export function getVisibleStaffList(data) {
  return request({
    url: 'admin/processManagement/list/users',
    method: 'post',
    data
  });
}

// 合同-同步账号信息
export function contractAccountSync(data) {
  return request({
    url: 'admin/contract/accountsSync',
    method: 'post',
    data
  });
}

// 合同管理 - 查看身份证记录操作日志
export function contractLogOperation(params) {
  return request({
    url: 'admin/contract/log',
    method: 'get',
    params
  });
}

// 记录合同附件下载操作
export function attachmentDownload(data) {
  return request({
    url: 'admin/contract/attachment/download',
    method: 'post',
    data
  });
}
